import http from '@/utils/http'

export function FillAddress(params: {
  address?: string
  name?: string
  phone: string
}) {
  return http.post(`/api/contac/ka-moji/address`, params)
}

export interface RewardRes {
  id: number
  user_id: number
  type: number
  lottery_result: number
  phone: string
  name: string
  address: string
  prize_name: string
  prize_img: string
}

/**
 * 奖励接口
 * @returns {Promise<RewardRes>} 获取奖励返回的数据
 */
export function Reward() {
  return http.post(`/api/contac/ka-moji/reward`).then<RewardRes>(res => res?.data)
}

export interface RewardV2Res {
  code: 0 | 41 | 42 | 43 // 0=正常抽奖，返回抽奖信息 41 验证码错误 42 抽奖用完 43 用户错误
  data: RewardRes & string
  state: 'ok' | 'fail'
}

export function RewardV2(): Promise<RewardV2Res> {
  return http.post(`/api/contac/ka-moji/rewardV2`)
}

export function RewardLog() {
  return http.get(`/api/contac/ka-moji/rewardLog`).then<{
    id: number
    user_id: number
    type: number
    lottery_result: number
    phone: string
    name: string
    address: string
    code: string
    prize_name: string
    prize_img: string
  }>(res => res?.data || '')
}

export function GetPrizes() {
  return http.get(`/api/contac/ka-moji/prizes`).then<
    {
      id: number
      name: string
      num: number
      probability: number
      img: string
      priority: number
      day_max: number
      type: number
      code_type: number
      brand: string
    }[]
  >(res => res?.data)
}

// #生成海报
export function RenderPoster(params: {
  url: string
}) {
  return http.post(`/api/contac/ka-moji/poster`, params).then<string>(res => res?.data)
}
